﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Black.Minecraft.Editor.ViewModels.Core;
using Black.NBT;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows;

namespace Black.Minecraft.Editor.ViewModels.DataModels
{
    /// <summary>
    /// DataModel pour l'inventaire
    /// </summary>
    public class InventoryDataModel : BaseViewModel
    {
        #region Propriétés

        /// <summary>
        /// Obtient si une sélection est en cours
        /// </summary>
        public bool HaveSelection
        {
            get
            {
                return (this._selection != null);
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar1
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar1);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar1);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar1);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar1, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar2
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar2);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar2);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar2);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar2, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar3
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar3);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar3);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar3);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar3, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar4
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar4);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar4);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar4);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar4, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar5
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar5);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar5);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar5);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar1, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar6
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar6);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar6);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar6);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar6, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar7
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar7);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar7);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar7);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar7, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar8
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar8);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar8);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar8);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar8, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel ActionBar9
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.ActionBar9);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.ActionBar9);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.ActionBar9);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.ActionBar9, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag11
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag11);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag11);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag11);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag11, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag12
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag12);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag12);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag12);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag12, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag13
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag13);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag13);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag13);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag13, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag14
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag14);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag14);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag14);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag14, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag15
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag15);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag15);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag15);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag15, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag16
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag16);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag16);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag16);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag16, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag17
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag17);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag17);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag17);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag17, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag18
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag18);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag18);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag18);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag18, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag19
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag19);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag19);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag19);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag19, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag21
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag21);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag21);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag21);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag21, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag22
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag22);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag22);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag22);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag22, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag23
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag23);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag23);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag23);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag23, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag24
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag24);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag24);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag24);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag24, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag25
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag25);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag25);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag25);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag25, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag26
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag26);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag26);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag26);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag26, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag27
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag27);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag27);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag27);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag27, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag28
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag28);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag28);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag28);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag28, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag29
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag29);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag29);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag29);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag29, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag31
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag31);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag31);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag31);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag31, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag32
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag32);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag32);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag32);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag32, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag33
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag33);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag33);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag33);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag33, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag34
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag34);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag34);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag34);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag34, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag35
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag35);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag35);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag35);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag35, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag36
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag36);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag36);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag36);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag36, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag37
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag37);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag37);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag37);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag37, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag38
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag38);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag38);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag38);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag38, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Bag39
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Bag39);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Bag39);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Bag39);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Bag39, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit la commande de suppression d'un item
        /// </summary>
        public ICommand DeleteCommand
        {
            get
            {
                return (this._deleteCommand);
            }
        }

        /// <summary>
        /// Obtient ou définit la de drop d'un item
        /// </summary>
        public ICommand DropCommand
        {
            get
            {
                return (this._dropCommand);
            }
        }

        /// <summary>
        /// Obtient ou définit la commande de gestion des enchantements d'un item
        /// </summary>
        public ICommand EnchantCommand
        {
            get
            {
                return (this._enchantCommand);
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Chest
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Chest);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Chest);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Chest);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Chest, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Feet
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Feet);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Feet);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Feet);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Feet, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Head
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Head);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Head);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Head);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Head, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item de ce slot
        /// </summary>
        public InventoryItemDataModel Leg
        {
            get
            {
                InventoryItemDataModel item = this.GetItemInSlot(SlotsEnum.Leg);

                if (item == null)
                    item = new InventoryItemDataModel(SlotsEnum.Leg);

                return (item);
            }
            set
            {
                InventoryItemDataModel current = this.GetItemInSlot(SlotsEnum.Leg);

                if (current != value)
                {
                    this.SetItemInSlot(SlotsEnum.Leg, value);
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit le nombre de l'élément
        /// </summary>
        public ObservableCollection<InventoryItemDataModel> Items
        {
            get
            {
                return (this._items);
            }
            set
            {
                if (this._items != value)
                {
                    this._items = value;
                    this.OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// Obtient ou définit l'item en cour de sélection
        /// </summary>
        public InventoryItemDataModel Selection
        {
            get
            {
                return (this._selection);
            }
            set
            {
                if (this._selection != value)
                {
                    this._selection = value;
                    this.OnPropertyChanged();
                    this.OnPropertyChanged("HaveSelection");
                }
            }
        }

        /// <summary>
        /// Obtient ou définit la commande de réparation globale
        /// </summary>
        public ICommand RepairAllCommand
        {
            get
            {
                return (this._repairAllCommand);
            }
        }

        /// <summary>
        /// Obtient ou définit la commande de réparation d'un item
        /// </summary>
        public ICommand RepairCommand
        {
            get
            {
                return (this._repairCommand);
            }
        }

        /// <summary>
        /// Obtient ou définit la commande de sélection
        /// </summary>
        public ICommand SelectionCommand
        {
            get
            {
                return (this._selectionCommand);
            }
        }

        /// <summary>
        /// Obtient ou définit la commande de mise en stack max d'un item
        /// </summary>
        public ICommand UpStackCommand
        {
            get
            {
                return (this._upStackCommand);
            }
        }

        #endregion

        #region Variables d'instances

        private TagList _data;
        private InventoryItemDataModel _selection;
        private ObservableCollection<InventoryItemDataModel> _items;

        private RelayCommand _selectionCommand;
        private RelayCommand _repairAllCommand;
        private RelayCommand _repairCommand;
        private RelayCommand _upStackCommand;
        private RelayCommand _deleteCommand;
        private RelayCommand _dropCommand;
        private RelayCommand<EnchantDataModel> _enchantCommand;

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        /// <param name="data">Source de donnée</param>
        public InventoryDataModel(TagList data)
            : base()
        {
            // Vérification

            if (data == null)
                throw (new ArgumentNullException("data", "The inventory node is corrupted or does not exist."));

            // Initialisation de la source de donnée

            this._data = data;

            // Extraction des éléments

            this._items = new ObservableCollection<InventoryItemDataModel>();

            foreach (TagCompound item in this._data.Items)
                this._items.Add(new InventoryItemDataModel(item));
        }

        #endregion

        #region Fonctions publiques

        /// <summary>
        /// Retourne la source de donnée
        /// </summary>
        /// <returns>Instance de la source de donnée</returns>
        public TagList GetData()
        {
            return (this._data);
        }

        #endregion

        #region Fonctions protégées

        /// <summary>
        /// Initialise les commandes
        /// </summary>
        protected override void OnInitializeCommand()
        {
            this._repairAllCommand = new RelayCommand(this.OnRepairAllCommandExecute);
            this._selectionCommand = new RelayCommand(this.OnSelectionCommandExecute);
            this._repairCommand = new RelayCommand(this.OnRepairCommandExecute);
            this._upStackCommand = new RelayCommand(this.OnUpStackCommandExecute);
            this._deleteCommand = new RelayCommand(this.OnDeleteCommandExecute);
            this._dropCommand = new RelayCommand(this.OnDropCommandExecute);
            this._enchantCommand = new RelayCommand<EnchantDataModel>(this.OnEnchantCommandExecute);
        }

        #endregion

        #region Fonctions privées

        /// <summary>
        /// Récupère l'élément à un slot donnée
        /// </summary>
        /// <param name="slotId">Identifiant du slot</param>
        /// <returns>Instance du slot</returns>
        private InventoryItemDataModel GetItemInSlot(SlotsEnum slotId)
        {
            InventoryItemDataModel item = (from p in this._items
                                           where p.Slot == slotId
                                           select p).FirstOrDefault();

            return (item);
        }

        /// <summary>
        /// Se produit sur l'éxécution de la commande de gestion des enchantements de l'item
        /// </summary>
        /// <param name="parameter">Paramètre de la commande</param>
        private void OnEnchantCommandExecute(EnchantDataModel parameter)
        {
            MainViewModel.Instance.ShowPopup(parameter);
        }

        /// <summary>
        /// Se produit sur l'éxécution de la commande de suppression de l'item
        /// </summary>
        /// <param name="parameter">Paramètre de la commande</param>
        private void OnDeleteCommandExecute(object parameter)
        {
            // Récupératon de l'élément

            InventoryItemDataModel item = this.Selection;

            // Supression ViewModel

            this._data.Items.Remove(item.GetData());
            this._items.Remove(item);

            // On retire la sélection

            this.Selection = null;

            // On retire de l'inventaire visuel

            this.OnPropertyChanged(item.Slot.ToString());

            // Mode modification

            MainViewModel.Instance.IsModified = true;
        }

        /// <summary>
        /// Se produit sur l'éxécution de la commande de drop de l'item
        /// </summary>
        /// <param name="parameter">Paramètre de la commande</param>
        private void OnDropCommandExecute(object parameter)
        {
            object[] list = (object[])parameter;

            // Récupération des informations

            ItemDataModel item = (ItemDataModel)list[0];
            SlotsEnum slot = (SlotsEnum)list[1];

            // Création de l'item 

            InventoryItemDataModel finalItem = new InventoryItemDataModel(InventoryItemDataModel.CreateItemTag(item.Id, item.Damage, slot));
            finalItem.Count = finalItem.Definition.MaxStack;

            // Ajout dans la liste

            this.SetItemInSlot(slot, finalItem);
            this.OnPropertyChanged(slot.ToString());
        }

        /// <summary>
        /// Se produit sur l'éxécution de la commande RepairAll
        /// </summary>
        /// <param name="parameter">Paramètre de la commande</param>
        private void OnRepairAllCommandExecute(object parameter)
        {
            foreach (InventoryItemDataModel item in this._items)
            {
                if (item.Definition.CanRepair && item.Damage > 0)
                {
                    item.Damage = 0;
                    MainViewModel.Instance.IsModified = true;
                }
            }
        }

        /// <summary>
        /// Se produit sur l'éxécution de la commande de réparation de l'item
        /// </summary>
        /// <param name="parameter">Paramètre de la commande</param>
        private void OnRepairCommandExecute(object parameter)
        {
            // Récupératon de l'élément

            InventoryItemDataModel item = this.Selection;

            // Réparation de l'élément

            if (item.Definition.CanRepair && item.Damage > 0)
            {
                item.Damage = 0;
                MainViewModel.Instance.IsModified = true;
            }
        }

        /// <summary>
        /// Se produit sur l'éxécution de la commande Selection
        /// </summary>
        /// <param name="parameter">Paramètre de la commande</param>
        private void OnSelectionCommandExecute(object parameter)
        {
            foreach (InventoryItemDataModel item in this._items)
                item.IsSelected = false;

            this.Selection = parameter as InventoryItemDataModel;

            if (this.Selection != null && this.Selection.ID > 0)
                this.Selection.IsSelected = true;
            else
                this.Selection = null;
        }

        /// <summary>
        /// Se produit sur l'éxécution de la commande de mise en stack max de l'item
        /// </summary>
        /// <param name="parameter">Paramètre de la commande</param>
        private void OnUpStackCommandExecute(object parameter)
        {
            // Récupératon de l'élément

            InventoryItemDataModel item = this.Selection;

            // Mise au max du stack de l'élément

            if (item.Count < item.Definition.MaxStack)
            {
                item.Count = item.Definition.MaxStack;
                MainViewModel.Instance.IsModified = true;
            }
        }

        /// <summary>
        /// Sauvegarde un élément
        /// </summary>
        /// <param name="slotId">Identifiant du slot</param>
        /// <param name="data">Instance des données a affecter</param>
        private void SetItemInSlot(SlotsEnum slotId, InventoryItemDataModel data)
        {
            InventoryItemDataModel item = (from p in this._items
                                           where p.Slot == slotId
                                           select p).FirstOrDefault();

            if (item != null)
            {
                this._data.Items.Remove(item.GetData());
                this._items.Remove(item);
            }

            this._data.Items.Add(data.GetData());
            this._items.Add(data);
        }

        #endregion
    }
}
